package serveur.agence;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import prog.AgenceImp;
import prog.AgenceItf;

public class ServeurAgenceMarseille {
	public static void main(String[] args) throws Exception {		
		Registry registry = null;
		try{
			registry = LocateRegistry.createRegistry(1099);
			AgenceImp agenceImp = new AgenceImp("MARSEILLE");
			AgenceItf agenceItf = (AgenceItf) UnicastRemoteObject.exportObject(agenceImp, 1099);
			registry.rebind("MARSEILLE", agenceItf);
		} catch(Exception e) {
			registry = LocateRegistry.getRegistry(1099);
		}
		
		
		Thread.currentThread().sleep(3000);
		
		Registry registryParis = LocateRegistry.getRegistry("172.19.1.32", 1099);
		AgenceItf refObjDistant = (AgenceItf) registryParis.lookup("PARIS");
		
		
		
		System.out.println(refObjDistant.estimerPrix("PARIS", "MARSEILLE", "Camion"));
		int numCommande = refObjDistant.creerCommande("PARIS", "MARSEILLE", "Camion", "23/05/2012");
		
		System.out.println(refObjDistant.afficherCommande(numCommande));
		refObjDistant.modifierDateDepart(numCommande, "25/05/2012");
		refObjDistant.modifierVehicule(numCommande, "Train");
		refObjDistant.modifierVilleArrive(numCommande, "TOULOUSE");
		System.out.println(refObjDistant.afficherCommande(numCommande));
		
		System.out.println(refObjDistant.finirCommande(0));
		
		/****** TEST ******/
		/*Registry registry4;
		try {
			registry4 = LocateRegistry.getRegistry(1099);
			System.out.println("Creation 1099");
		} catch (RemoteException e) {
			registry4 = LocateRegistry.createRegistry(1099);
		}
		registry4.rebind("MARSEILLE", agenceItf);
		
		Registry registry3 = LocateRegistry.getRegistry(1099);
		AgenceItf agenceItf2 = (AgenceItf) registry.lookup("PARIS");
		
		agenceItf2.test();*/
		/****** TEST ******/
	}
}
